﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="LazyContent.cs" company="Anton Frattaroli">
//   Copyright (c) Anton Frattaroli. All rights reserved.
// </copyright>
// <summary>
//   Defines the LazyContent class.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
namespace Lidocaine.Data
{
    using System;
    using Lidocaine.BusinessObjects;
    
    /// <summary>
    /// Defines the LazyContent class.
    /// </summary>
    public class LazyContent : BusinessObjects.Content
    {
        /// <summary>
        /// Gets or sets the host PageLayout.
        /// </summary>
        public override BusinessObjects.PageLayout PageLayout
        {
            get
            {
                if (base.PageLayout == null && this.PageId != 0)
                {
                    base.PageLayout = Data.PageLayout.Select(this.PageId);
                }

                return base.PageLayout;
            }

            set
            {
                base.PageLayout = value;
                if (value != null)
                {
                    this.PageId = value.Id;
                }
                else
                {
                    this.PageId = 0;
                }
            }
        }

        /// <summary>
        /// Gets or sets the author Profile.
        /// </summary>
        public override BusinessObjects.UserProfile Author
        {
            get
            {
                if (base.Author == null && this.AuthorId != 0)
                {
                    base.Author = Data.UserProfile.Select(this.AuthorId);
                }

                return base.Author;
            }

            set
            {
                base.Author = value;
                if (value != null)
                {
                    this.AuthorId = value.Id;
                }
                else
                {
                    this.AuthorId = 0;
                }
            }
        }
    }
}